var init1 = (function(){
    // 考点：变量提升（暂时性死区）
    var x = 1;
    {
        // let x = x;
        // console.log(x); 
    }

    // function foo(x, y) {
    //     // 有弊端，当x=y=0时，有问题
    //     x = x || 1;
    //     y = y || 2;
    //     console.log(x + y);
    // }

    // 解
    function foo(x = 1, y = 2){
        console.log(x + y);
    }
});

var init2 = (function(){
    // 报错
    // function bar(x = 2){
    //     let x = 2;
    //     console.log(x);
    // }

    // 报错
    // let x = 1;
    // function bar(x = x){
    //     console.log(x);
    // }
    // bar()
    

    // let x = 1;
    // function foo(y = x){
    //     let x = 2;
    //     console.log(y);
    // }

    // foo()

    // function foo(x = 2) {
    //     let x = 2;
    //     console.log(x);
    // }
    // foo()
})();

// 解构
var initJieGou = (function(){
    // 模式匹配（结构化赋值）
    let [a, b, c] = [1, 2, 3];
    console.log(a, b, c);

    let [d, [e], [[f]]] = [1, [2], [[3]]];
    console.log(d, e, f);

    console.log('----分隔线---');

    let [aa = 6] = [1];
    let [bb = 6] = [];
    console.log(aa, bb);

    let [cc, dd = 2] = [1];
    console.log(cc, dd);

    // 除undefined之外，其他的都是填啥返啥
    let [ee, ff = 2] = [1, null];
    console.log(ee, ff);

    function test(){
        console.log(10);
    }
    // let [gg = test()] = [1];
    let [gg = test()] = [];
    console.log(gg);

    // let x = 1; // 报错，重复定义
    let [x = 1, y = x] = [];
    console.log(x, y);
});

// 对象解构赋值
var initObjJieGou = (function(){
    // var age = 14;
    // var person = {
    //     name: '张三',
    //     age: age,
    //     sex: 'male',
    //     eat(){ // es6简写
    //         console.log(1);
    //     }
    // }
    // console.log(person);

    // let firstName = '赵';
    // let secondName = '渝航';
    // let p = {
    //     [firstName + secondName]: '赵渝航'
    // }

    // console.log(p);

    let {a, b, c} = {a: 1, b: 2, c: 3};

    console.log(a, b, c);

    let arrObj = [
        {name: 'aaa'},
        {name: 'bbb'},
        {name: 'ccc'},
        {name: 'ddd'},
        {name: 'eee'},
        {name: 'fff'}
    ]
    let [{name}] = arrObj
    console.log(name);

    let person = {
        son: {
            name: '张三',
            age: 18
        },
        car: {
            brand: 'Banz',
            color: 'red'
        }
    }
    const { son, car } = person;
    console.log(son);
    console.log('--------------');
    console.log(car);
});

var initParam = function(){
    // init1();
    // init2();
    // initJieGou();
    initObjJieGou();
}

initParam();